{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Synthesize search sessions from signals\n",
    "\n",
    "This notebook synthesizes search sessions from the CTR of the clicked documents on each search result. It's assumed that if you order results by CTR, that roughly captures the source search system's relevance ranking in aggregate (including all the position and other biases). \n",
    "\n",
    "You can then check to see if the document is above or below average for that rank position (using a z score). You can then use that z score to translate that document to any other position. \n",
    "\n",
    "This is intended more for creating fake search session data for examples in AI Powered Search, and not a replacement for actually logging real search sessions in your search system."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\"query_id\",\"user\",\"type\",\"target\",\"signal_time\"\r\n",
      "\"u2_0_1\",\"u2\",\"query\",\"nook\",\"2019-07-31 08:49:07.3116\"\r\n",
      "\"u2_1_2\",\"u2\",\"query\",\"rca\",\"2020-05-04 08:28:21.1848\"\r\n",
      "\"u3_0_1\",\"u3\",\"query\",\"macbook\",\"2019-12-22 00:07:07.0152\"\r\n",
      "\"u4_0_1\",\"u4\",\"query\",\"Tv antenna\",\"2019-08-22 23:45:54.1030\"\r\n",
      "\"u5_0_1\",\"u5\",\"query\",\"AC power cord\",\"2019-10-20 08:27:00.1600\"\r\n",
      "\"u6_0_1\",\"u6\",\"query\",\"Watch The Throne\",\"2019-09-18 11:59:53.7470\"\r\n",
      "\"u7_0_1\",\"u7\",\"query\",\"Camcorder\",\"2020-02-25 13:02:29.3089\"\r\n",
      "\"u9_0_1\",\"u9\",\"query\",\"wireless headphones\",\"2020-04-26 04:26:09.7198\"\r\n",
      "\"u10_0_1\",\"u10\",\"query\",\"Xbox\",\"2019-09-13 16:26:12.0132\"\r\n"
     ]
    }
   ],
   "source": [
    "! cd ../../data/retrotech && head signals.csv\n",
    "\n",
    "import random\n",
    "import pandas \n",
    "import numpy\n",
    "import sys\n",
    "sys.path.append('../..')\n",
    "from aips import *\n",
    "from ch11.session_gen import SessionGenerator\n",
    "import os\n",
    "from IPython.display import display,HTML\n",
    "\n",
    "#seed=8675309\n",
    "#random.seed(seed)\n",
    "#numpy.random.seed(seed)\n",
    "\n",
    "DOCS_PER_SESSION=15 # how many docs in one search page view?\n",
    "NUM_SESSIONS=5000 # how many sessions to generate for each query?\n",
    "\n",
    "# Generate search sessions for these queries\n",
    "QUERIES_TO_SIMULATE=['dryer', 'iphone', 'ipad', 'transformers dark of the moon']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/jovyan/notebooks/ch11/../session_gen.py:45: DtypeWarning: Columns (3) have mixed types. Specify dtype option on import or set low_memory=False.\n",
      "  signals = pandas.read_csv(signals_path)\n",
      "/home/jovyan/notebooks/ch11/../session_gen.py:12: UserWarning: Boolean Series key will be reindexed to match DataFrame index.\n",
      "  pop_query_events = signals[signals['type'] == 'query'][signals['target'].isin(popular_queries)]\n",
      "/home/jovyan/notebooks/ch11/../session_gen.py:94: FutureWarning: The 'mad' method is deprecated and will be removed in a future version. To compute the same result, you may do `(df - df.mean()).abs().mean()`.\n",
      "  canonical_rankings[canonical_rankings['rank'] == i]['ctr'].mad()\n",
      "/home/jovyan/notebooks/ch11/../session_gen.py:94: FutureWarning: The 'mad' method is deprecated and will be removed in a future version. To compute the same result, you may do `(df - df.mean()).abs().mean()`.\n",
      "  canonical_rankings[canonical_rankings['rank'] == i]['ctr'].mad()\n",
      "/home/jovyan/notebooks/ch11/../session_gen.py:150: UserWarning: Boolean Series key will be reindexed to match DataFrame index.\n",
      "  canonical = self.canonical_rankings[self.canonical_rankings['query'] == query][self.canonical_rankings['rank'] < num_docs]\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>posn_ctr_mean</th>\n",
       "      <th>posn_ctr_std</th>\n",
       "      <th>dest_rank</th>\n",
       "      <th>posn_ctr_mad</th>\n",
       "      <th>posn_ctr_median</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>70426</th>\n",
       "      <td>0.118271</td>\n",
       "      <td>0.071206</td>\n",
       "      <td>1</td>\n",
       "      <td>0.054286</td>\n",
       "      <td>0.105263</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70427</th>\n",
       "      <td>0.029738</td>\n",
       "      <td>0.018342</td>\n",
       "      <td>6</td>\n",
       "      <td>0.014968</td>\n",
       "      <td>0.029126</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70428</th>\n",
       "      <td>0.061092</td>\n",
       "      <td>0.034642</td>\n",
       "      <td>3</td>\n",
       "      <td>0.027316</td>\n",
       "      <td>0.056936</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70429</th>\n",
       "      <td>0.047945</td>\n",
       "      <td>0.028633</td>\n",
       "      <td>4</td>\n",
       "      <td>0.022603</td>\n",
       "      <td>0.044779</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70430</th>\n",
       "      <td>0.015450</td>\n",
       "      <td>0.010633</td>\n",
       "      <td>10</td>\n",
       "      <td>0.009189</td>\n",
       "      <td>0.013268</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70431</th>\n",
       "      <td>0.223624</td>\n",
       "      <td>0.179218</td>\n",
       "      <td>0</td>\n",
       "      <td>0.134325</td>\n",
       "      <td>0.165036</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70432</th>\n",
       "      <td>0.082040</td>\n",
       "      <td>0.047044</td>\n",
       "      <td>2</td>\n",
       "      <td>0.037050</td>\n",
       "      <td>0.074324</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70433</th>\n",
       "      <td>0.038391</td>\n",
       "      <td>0.023441</td>\n",
       "      <td>5</td>\n",
       "      <td>0.018783</td>\n",
       "      <td>0.036580</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70434</th>\n",
       "      <td>0.020638</td>\n",
       "      <td>0.013713</td>\n",
       "      <td>8</td>\n",
       "      <td>0.011544</td>\n",
       "      <td>0.019349</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70435</th>\n",
       "      <td>0.017740</td>\n",
       "      <td>0.011945</td>\n",
       "      <td>9</td>\n",
       "      <td>0.010182</td>\n",
       "      <td>0.016393</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70436</th>\n",
       "      <td>0.013733</td>\n",
       "      <td>0.009464</td>\n",
       "      <td>11</td>\n",
       "      <td>0.008172</td>\n",
       "      <td>0.010714</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70437</th>\n",
       "      <td>0.024395</td>\n",
       "      <td>0.015588</td>\n",
       "      <td>7</td>\n",
       "      <td>0.013035</td>\n",
       "      <td>0.024221</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70438</th>\n",
       "      <td>0.012303</td>\n",
       "      <td>0.008425</td>\n",
       "      <td>12</td>\n",
       "      <td>0.007286</td>\n",
       "      <td>0.009346</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70439</th>\n",
       "      <td>0.011122</td>\n",
       "      <td>0.007520</td>\n",
       "      <td>13</td>\n",
       "      <td>0.006494</td>\n",
       "      <td>0.008439</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70440</th>\n",
       "      <td>0.010175</td>\n",
       "      <td>0.006723</td>\n",
       "      <td>14</td>\n",
       "      <td>0.005787</td>\n",
       "      <td>0.007782</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       posn_ctr_mean  posn_ctr_std  dest_rank  posn_ctr_mad  posn_ctr_median\n",
       "70426       0.118271      0.071206          1      0.054286         0.105263\n",
       "70427       0.029738      0.018342          6      0.014968         0.029126\n",
       "70428       0.061092      0.034642          3      0.027316         0.056936\n",
       "70429       0.047945      0.028633          4      0.022603         0.044779\n",
       "70430       0.015450      0.010633         10      0.009189         0.013268\n",
       "70431       0.223624      0.179218          0      0.134325         0.165036\n",
       "70432       0.082040      0.047044          2      0.037050         0.074324\n",
       "70433       0.038391      0.023441          5      0.018783         0.036580\n",
       "70434       0.020638      0.013713          8      0.011544         0.019349\n",
       "70435       0.017740      0.011945          9      0.010182         0.016393\n",
       "70436       0.013733      0.009464         11      0.008172         0.010714\n",
       "70437       0.024395      0.015588          7      0.013035         0.024221\n",
       "70438       0.012303      0.008425         12      0.007286         0.009346\n",
       "70439       0.011122      0.007520         13      0.006494         0.008439\n",
       "70440       0.010175      0.006723         14      0.005787         0.007782"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "session_gen = SessionGenerator(signals_path='../../data/retrotech/signals.csv', min_query_count=100)\n",
    "session_gen('transformers dark of the moon', num_docs=DOCS_PER_SESSION)\n",
    "session_gen.random_rankings['transformers dark of the moon']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Randomly sample source signals, generate new sessions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "../session_gen.py:157: UserWarning: Boolean Series key will be reindexed to match DataFrame index.\n",
      "  canonical = self.canonical_rankings[self.canonical_rankings['query'] == query][self.canonical_rankings['rank'] < num_docs]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Created Sessions 0 Last Query transformers dark of the moon Elapsed 0.02069779997691512\n",
      "Created Sessions 500 Last Query transformers dark of the moon Elapsed 7.948518699966371\n",
      "Created Sessions 1000 Last Query transformers dark of the moon Elapsed 16.04209959995933\n",
      "Created Sessions 1500 Last Query transformers dark of the moon Elapsed 24.25959489995148\n",
      "Created Sessions 2000 Last Query transformers dark of the moon Elapsed 32.66837129998021\n",
      "Created Sessions 2500 Last Query transformers dark of the moon Elapsed 40.64491539995652\n",
      "Created Sessions 3000 Last Query transformers dark of the moon Elapsed 48.351152800023556\n",
      "Created Sessions 3500 Last Query transformers dark of the moon Elapsed 55.67575059994124\n",
      "Created Sessions 4000 Last Query transformers dark of the moon Elapsed 62.9664745000191\n",
      "Created Sessions 4500 Last Query transformers dark of the moon Elapsed 70.29577289998997\n"
     ]
    }
   ],
   "source": [
    "from time import perf_counter \n",
    "\n",
    "for query in ['transformers dark of the moon']:\n",
    "    \n",
    "    session_dfs=[]\n",
    "    t1_start = perf_counter()  \n",
    "    for i in range(0, NUM_SESSIONS):\n",
    "        session_dfs.append(session_gen(query, use_median=True, dampen=1.0, num_docs=DOCS_PER_SESSION))\n",
    "        if (i % 500 == 0):\n",
    "            print(\"Created Sessions %s Last Query %s Elapsed %s\" % (i, query, perf_counter()-t1_start))\n",
    "\n",
    "    sessions = pandas.concat(session_dfs)\n",
    "    sessions = sessions.sort_values(['sess_id', 'dest_rank'])\n",
    "    sessions[['sess_id', 'query', 'dest_rank', 'clicked_doc_id', 'clicked']] \\\n",
    "        .rename(columns={'dest_rank': 'rank'}) \\\n",
    "        .to_csv(\"%s_sessions.gz\" % query, compression='gzip', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>index</th>\n",
       "      <th>query</th>\n",
       "      <th>clicked_doc_id</th>\n",
       "      <th>click_count</th>\n",
       "      <th>tot_query_count</th>\n",
       "      <th>ctr</th>\n",
       "      <th>rank</th>\n",
       "      <th>posn_ctr_mean</th>\n",
       "      <th>posn_ctr_std</th>\n",
       "      <th>posn_ctr_median</th>\n",
       "      <th>posn_ctr_mad</th>\n",
       "      <th>ctr_std_z_score</th>\n",
       "      <th>ctr_mod_z_score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>70426</th>\n",
       "      <td>71842</td>\n",
       "      <td>transformers dark of the moon</td>\n",
       "      <td>97360810042</td>\n",
       "      <td>99</td>\n",
       "      <td>147</td>\n",
       "      <td>0.673469</td>\n",
       "      <td>0</td>\n",
       "      <td>0.223624</td>\n",
       "      <td>0.179218</td>\n",
       "      <td>0.165036</td>\n",
       "      <td>0.134325</td>\n",
       "      <td>2.510042</td>\n",
       "      <td>3.785084</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70427</th>\n",
       "      <td>71844</td>\n",
       "      <td>transformers dark of the moon</td>\n",
       "      <td>97363560449</td>\n",
       "      <td>19</td>\n",
       "      <td>147</td>\n",
       "      <td>0.129252</td>\n",
       "      <td>1</td>\n",
       "      <td>0.118271</td>\n",
       "      <td>0.071206</td>\n",
       "      <td>0.105263</td>\n",
       "      <td>0.054286</td>\n",
       "      <td>0.154203</td>\n",
       "      <td>0.441894</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70428</th>\n",
       "      <td>71835</td>\n",
       "      <td>transformers dark of the moon</td>\n",
       "      <td>25192107191</td>\n",
       "      <td>6</td>\n",
       "      <td>147</td>\n",
       "      <td>0.040816</td>\n",
       "      <td>2</td>\n",
       "      <td>0.082040</td>\n",
       "      <td>0.047044</td>\n",
       "      <td>0.074324</td>\n",
       "      <td>0.037050</td>\n",
       "      <td>-0.876281</td>\n",
       "      <td>-0.904408</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70429</th>\n",
       "      <td>71838</td>\n",
       "      <td>transformers dark of the moon</td>\n",
       "      <td>47875841420</td>\n",
       "      <td>6</td>\n",
       "      <td>147</td>\n",
       "      <td>0.040816</td>\n",
       "      <td>3</td>\n",
       "      <td>0.061092</td>\n",
       "      <td>0.034642</td>\n",
       "      <td>0.056936</td>\n",
       "      <td>0.027316</td>\n",
       "      <td>-0.585299</td>\n",
       "      <td>-0.590120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70430</th>\n",
       "      <td>71846</td>\n",
       "      <td>transformers dark of the moon</td>\n",
       "      <td>786936817218</td>\n",
       "      <td>4</td>\n",
       "      <td>147</td>\n",
       "      <td>0.027211</td>\n",
       "      <td>4</td>\n",
       "      <td>0.047945</td>\n",
       "      <td>0.028633</td>\n",
       "      <td>0.044779</td>\n",
       "      <td>0.022603</td>\n",
       "      <td>-0.724128</td>\n",
       "      <td>-0.777255</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70431</th>\n",
       "      <td>71840</td>\n",
       "      <td>transformers dark of the moon</td>\n",
       "      <td>47875842335</td>\n",
       "      <td>2</td>\n",
       "      <td>147</td>\n",
       "      <td>0.013605</td>\n",
       "      <td>5</td>\n",
       "      <td>0.038391</td>\n",
       "      <td>0.023441</td>\n",
       "      <td>0.036580</td>\n",
       "      <td>0.018783</td>\n",
       "      <td>-1.057352</td>\n",
       "      <td>-1.223175</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70432</th>\n",
       "      <td>71848</td>\n",
       "      <td>transformers dark of the moon</td>\n",
       "      <td>047875841406</td>\n",
       "      <td>2</td>\n",
       "      <td>147</td>\n",
       "      <td>0.013605</td>\n",
       "      <td>6</td>\n",
       "      <td>0.029738</td>\n",
       "      <td>0.018342</td>\n",
       "      <td>0.029126</td>\n",
       "      <td>0.014968</td>\n",
       "      <td>-0.879573</td>\n",
       "      <td>-1.036929</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70433</th>\n",
       "      <td>71833</td>\n",
       "      <td>transformers dark of the moon</td>\n",
       "      <td>24543701538</td>\n",
       "      <td>1</td>\n",
       "      <td>147</td>\n",
       "      <td>0.006803</td>\n",
       "      <td>7</td>\n",
       "      <td>0.024395</td>\n",
       "      <td>0.015588</td>\n",
       "      <td>0.024221</td>\n",
       "      <td>0.013035</td>\n",
       "      <td>-1.128557</td>\n",
       "      <td>-1.336316</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70434</th>\n",
       "      <td>71834</td>\n",
       "      <td>transformers dark of the moon</td>\n",
       "      <td>24543750949</td>\n",
       "      <td>1</td>\n",
       "      <td>147</td>\n",
       "      <td>0.006803</td>\n",
       "      <td>8</td>\n",
       "      <td>0.020638</td>\n",
       "      <td>0.013713</td>\n",
       "      <td>0.019349</td>\n",
       "      <td>0.011544</td>\n",
       "      <td>-1.008924</td>\n",
       "      <td>-1.086823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70435</th>\n",
       "      <td>71836</td>\n",
       "      <td>transformers dark of the moon</td>\n",
       "      <td>36725235564</td>\n",
       "      <td>1</td>\n",
       "      <td>147</td>\n",
       "      <td>0.006803</td>\n",
       "      <td>9</td>\n",
       "      <td>0.017740</td>\n",
       "      <td>0.011945</td>\n",
       "      <td>0.016393</td>\n",
       "      <td>0.010182</td>\n",
       "      <td>-0.915664</td>\n",
       "      <td>-0.941942</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70436</th>\n",
       "      <td>71837</td>\n",
       "      <td>transformers dark of the moon</td>\n",
       "      <td>47875841369</td>\n",
       "      <td>1</td>\n",
       "      <td>147</td>\n",
       "      <td>0.006803</td>\n",
       "      <td>10</td>\n",
       "      <td>0.015450</td>\n",
       "      <td>0.010633</td>\n",
       "      <td>0.013268</td>\n",
       "      <td>0.009189</td>\n",
       "      <td>-0.813256</td>\n",
       "      <td>-0.703614</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70437</th>\n",
       "      <td>71839</td>\n",
       "      <td>transformers dark of the moon</td>\n",
       "      <td>47875842328</td>\n",
       "      <td>1</td>\n",
       "      <td>147</td>\n",
       "      <td>0.006803</td>\n",
       "      <td>11</td>\n",
       "      <td>0.013733</td>\n",
       "      <td>0.009464</td>\n",
       "      <td>0.010714</td>\n",
       "      <td>0.008172</td>\n",
       "      <td>-0.732239</td>\n",
       "      <td>-0.478627</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70438</th>\n",
       "      <td>71841</td>\n",
       "      <td>transformers dark of the moon</td>\n",
       "      <td>93624956037</td>\n",
       "      <td>1</td>\n",
       "      <td>147</td>\n",
       "      <td>0.006803</td>\n",
       "      <td>12</td>\n",
       "      <td>0.012303</td>\n",
       "      <td>0.008425</td>\n",
       "      <td>0.009346</td>\n",
       "      <td>0.007286</td>\n",
       "      <td>-0.652823</td>\n",
       "      <td>-0.349046</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70439</th>\n",
       "      <td>71843</td>\n",
       "      <td>transformers dark of the moon</td>\n",
       "      <td>97363532149</td>\n",
       "      <td>1</td>\n",
       "      <td>147</td>\n",
       "      <td>0.006803</td>\n",
       "      <td>13</td>\n",
       "      <td>0.011122</td>\n",
       "      <td>0.007520</td>\n",
       "      <td>0.008439</td>\n",
       "      <td>0.006494</td>\n",
       "      <td>-0.574424</td>\n",
       "      <td>-0.251947</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70440</th>\n",
       "      <td>71845</td>\n",
       "      <td>transformers dark of the moon</td>\n",
       "      <td>400192926087</td>\n",
       "      <td>1</td>\n",
       "      <td>147</td>\n",
       "      <td>0.006803</td>\n",
       "      <td>14</td>\n",
       "      <td>0.010175</td>\n",
       "      <td>0.006723</td>\n",
       "      <td>0.007782</td>\n",
       "      <td>0.005787</td>\n",
       "      <td>-0.501635</td>\n",
       "      <td>-0.169248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70441</th>\n",
       "      <td>71847</td>\n",
       "      <td>transformers dark of the moon</td>\n",
       "      <td>044476821592</td>\n",
       "      <td>1</td>\n",
       "      <td>147</td>\n",
       "      <td>0.006803</td>\n",
       "      <td>15</td>\n",
       "      <td>0.009358</td>\n",
       "      <td>0.006036</td>\n",
       "      <td>0.007092</td>\n",
       "      <td>0.005126</td>\n",
       "      <td>-0.423396</td>\n",
       "      <td>-0.056471</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       index                          query clicked_doc_id  click_count  \\\n",
       "70426  71842  transformers dark of the moon    97360810042           99   \n",
       "70427  71844  transformers dark of the moon    97363560449           19   \n",
       "70428  71835  transformers dark of the moon    25192107191            6   \n",
       "70429  71838  transformers dark of the moon    47875841420            6   \n",
       "70430  71846  transformers dark of the moon   786936817218            4   \n",
       "70431  71840  transformers dark of the moon    47875842335            2   \n",
       "70432  71848  transformers dark of the moon   047875841406            2   \n",
       "70433  71833  transformers dark of the moon    24543701538            1   \n",
       "70434  71834  transformers dark of the moon    24543750949            1   \n",
       "70435  71836  transformers dark of the moon    36725235564            1   \n",
       "70436  71837  transformers dark of the moon    47875841369            1   \n",
       "70437  71839  transformers dark of the moon    47875842328            1   \n",
       "70438  71841  transformers dark of the moon    93624956037            1   \n",
       "70439  71843  transformers dark of the moon    97363532149            1   \n",
       "70440  71845  transformers dark of the moon   400192926087            1   \n",
       "70441  71847  transformers dark of the moon   044476821592            1   \n",
       "\n",
       "       tot_query_count       ctr  rank  posn_ctr_mean  posn_ctr_std  \\\n",
       "70426              147  0.673469     0       0.223624      0.179218   \n",
       "70427              147  0.129252     1       0.118271      0.071206   \n",
       "70428              147  0.040816     2       0.082040      0.047044   \n",
       "70429              147  0.040816     3       0.061092      0.034642   \n",
       "70430              147  0.027211     4       0.047945      0.028633   \n",
       "70431              147  0.013605     5       0.038391      0.023441   \n",
       "70432              147  0.013605     6       0.029738      0.018342   \n",
       "70433              147  0.006803     7       0.024395      0.015588   \n",
       "70434              147  0.006803     8       0.020638      0.013713   \n",
       "70435              147  0.006803     9       0.017740      0.011945   \n",
       "70436              147  0.006803    10       0.015450      0.010633   \n",
       "70437              147  0.006803    11       0.013733      0.009464   \n",
       "70438              147  0.006803    12       0.012303      0.008425   \n",
       "70439              147  0.006803    13       0.011122      0.007520   \n",
       "70440              147  0.006803    14       0.010175      0.006723   \n",
       "70441              147  0.006803    15       0.009358      0.006036   \n",
       "\n",
       "       posn_ctr_median  posn_ctr_mad  ctr_std_z_score  ctr_mod_z_score  \n",
       "70426         0.165036      0.134325         2.510042         3.785084  \n",
       "70427         0.105263      0.054286         0.154203         0.441894  \n",
       "70428         0.074324      0.037050        -0.876281        -0.904408  \n",
       "70429         0.056936      0.027316        -0.585299        -0.590120  \n",
       "70430         0.044779      0.022603        -0.724128        -0.777255  \n",
       "70431         0.036580      0.018783        -1.057352        -1.223175  \n",
       "70432         0.029126      0.014968        -0.879573        -1.036929  \n",
       "70433         0.024221      0.013035        -1.128557        -1.336316  \n",
       "70434         0.019349      0.011544        -1.008924        -1.086823  \n",
       "70435         0.016393      0.010182        -0.915664        -0.941942  \n",
       "70436         0.013268      0.009189        -0.813256        -0.703614  \n",
       "70437         0.010714      0.008172        -0.732239        -0.478627  \n",
       "70438         0.009346      0.007286        -0.652823        -0.349046  \n",
       "70439         0.008439      0.006494        -0.574424        -0.251947  \n",
       "70440         0.007782      0.005787        -0.501635        -0.169248  \n",
       "70441         0.007092      0.005126        -0.423396        -0.056471  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gset = session_gen.canonical_rankings\n",
    "orig_dryer = gset[gset['query'] == 'transformers dark of the moon']\n",
    "\n",
    "orig_dryer[orig_dryer['rank'] < 20]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#\n",
      "*\n",
      "1080p\n",
      "1196648\n",
      "1342081 1342106 1342115 1342124\n",
      "24\n",
      "300\n",
      "3547042\n",
      "360\n",
      "360 elite\n",
      "3d\n",
      "3d glasses\n",
      "3d movies\n",
      "3d tv\n",
      "3ds\n",
      "50 cent\n",
      "8800\n",
      "Acer\n",
      "Acer iconia\n",
      "Adele\n",
      "Alarm clock\n",
      "Alienware\n",
      "Alpine\n",
      "Amp\n",
      "Amplifier\n",
      "Android tablet\n",
      "Antenna\n",
      "Apple\n",
      "Apple computer\n",
      "Apple iPad\n",
      "Apple keyboard\n",
      "Apple laptop\n",
      "Apple laptops\n",
      "Apple tv\n",
      "Arkham city\n",
      "Asus\n",
      "Asus laptop\n",
      "Asus transformer\n",
      "Batman\n",
      "Batman arkham city\n",
      "Batman year one\n",
      "Battlefield\n",
      "Battlefield 3\n",
      "Beats\n",
      "Beats by Dre\n",
      "Beats by dr dre\n",
      "Beats by dre\n",
      "Beats headphones\n",
      "Big bang theory\n",
      "Blackberry\n",
      "Blackberry playbook\n",
      "Blink 182\n",
      "Blu ray\n",
      "Blu ray player\n",
      "Blue tooth\n",
      "Bluetooth\n",
      "Bluetooth headphones\n",
      "Bluetooth headset\n",
      "Boardwalk empire\n",
      "Boost mobile\n",
      "Bose\n",
      "Bose headphones\n",
      "Bridesmaids\n",
      "Cable modem\n",
      "Call of duty\n",
      "Camcorder\n",
      "Camera\n",
      "Cameras\n",
      "Canon\n",
      "Canon 7d\n",
      "Canon camera\n",
      "Captain America\n",
      "Captain america\n",
      "Car alarm\n",
      "Car audio\n",
      "Car radio\n",
      "Car speakers\n",
      "Car stereo\n",
      "Car stereos\n",
      "Carter 4\n",
      "Cell phones\n",
      "Coldplay\n",
      "Computer\n",
      "Computer speakers\n",
      "Computers\n",
      "D7000\n",
      "DVD player\n",
      "Dark souls\n",
      "Dazzle\n",
      "Dead island\n",
      "Dell\n",
      "Dell laptop\n",
      "Dell laptops\n",
      "Denon\n",
      "Desktop\n",
      "Deus ex\n",
      "Dexter\n",
      "Digital camera\n",
      "Dishwasher\n",
      "Dj\n",
      "Dr dre\n",
      "Dr dre beats\n",
      "Drake\n",
      "Dre beats\n",
      "Droid bionic\n",
      "Dsi\n",
      "Dsl modem\n",
      "Dumbo\n",
      "Dvr\n",
      "Dynex\n",
      "Dyson\n",
      "Earbuds\n",
      "Earphones\n",
      "Ethernet cable\n",
      "External hard drive\n",
      "FIFA 12\n",
      "Fast five\n",
      "Flash drive\n",
      "Flip\n",
      "Fm transmitter\n",
      "Freezer\n",
      "Galaxy\n",
      "Galaxy tab\n",
      "Garmin\n",
      "Garmin gps\n",
      "Gateway\n",
      "Gateway laptop\n",
      "Gears of war\n",
      "Gears of war 3\n",
      "Glee\n",
      "Go pro\n",
      "God of war\n",
      "Google tv\n",
      "Gopro\n",
      "Gps\n",
      "Graphics card\n",
      "Green lantern\n",
      "HP tablet\n",
      "HP touchpad\n",
      "HTC flyer\n",
      "Halloween\n",
      "Hard drive\n",
      "Harry potter\n",
      "Hdmi\n",
      "Hdmi cable\n",
      "Head phones\n",
      "Headphone\n",
      "Headphones\n",
      "Headset\n",
      "Hello kitty\n",
      "Home theater\n",
      "Horrible bosses\n",
      "How I met your mother\n",
      "Hp\n",
      "Hp laptop\n",
      "Hp laptops\n",
      "Hp tablet\n",
      "Hp touch\n",
      "Hp touch pad\n",
      "Hp touchpad\n",
      "Htc\n",
      "Htc flyer\n",
      "Htc tablet\n",
      "I pad\n",
      "I pad 2\n",
      "I phone 4s\n",
      "IPad\n",
      "IPad 2\n",
      "IPhone 4s\n",
      "Ico\n",
      "Ihome\n",
      "Imac\n",
      "Incase\n",
      "Insignia\n",
      "Ipad\n",
      "Ipad 2\n",
      "Ipad2\n",
      "Iphone\n",
      "Iphone 4\n",
      "Iphone 4 case\n",
      "Iphone 4s\n",
      "Ipod\n",
      "Ipod nano\n",
      "Ipod touch\n",
      "Itouch\n",
      "Jawbone\n",
      "Juicer\n",
      "Jurassic park\n",
      "Just dance\n",
      "Just dance 3\n",
      "Karaoke\n",
      "Kenwood\n",
      "Keurig\n",
      "Keyboard\n",
      "Kicker\n",
      "Kindle\n",
      "Kindle fire\n",
      "Kinect\n",
      "Klipsch\n",
      "Lap top\n",
      "Lap tops\n",
      "Laptop\n",
      "Laptop charger\n",
      "Laptops\n",
      "Led tv\n",
      "Lenovo\n",
      "Lg\n",
      "Lifeproof\n",
      "Lil Wayne\n",
      "Lil wayne\n",
      "Linksys\n",
      "Lion king\n",
      "Logitech\n",
      "Logitech revue\n",
      "Lord of the rings\n",
      "Mac\n",
      "Mac air\n",
      "Mac book\n",
      "Mac book air\n",
      "Mac book pro\n",
      "Mac laptop\n",
      "Mac mini\n",
      "MacBook\n",
      "MacBook air\n",
      "MacBook pro\n",
      "Macbook\n",
      "Macbook air\n",
      "Macbook pro\n",
      "Madden\n",
      "Madden 12\n",
      "Micro sd\n",
      "Microphone\n",
      "Microsoft office\n",
      "Microwave\n",
      "Mini fridge\n",
      "Modem\n",
      "Modems\n",
      "Modern warfare 3\n",
      "Monitor\n",
      "Monitors\n",
      "Mophie\n",
      "Motorola triumph\n",
      "Motorola xoom\n",
      "Mouse\n",
      "Mw3\n",
      "Netbook\n",
      "Netbooks\n",
      "Netgear\n",
      "Nikon\n",
      "Nikon 1\n",
      "Nikon camera\n",
      "Nikon d3100\n",
      "Nikon d5100\n",
      "Nikon d7000\n",
      "Nintendo 3ds\n",
      "Nintendo ds\n",
      "Nirvana\n",
      "Nook\n",
      "Nook color\n",
      "Notebook\n",
      "On star\n",
      "Onstar\n",
      "Otter box\n",
      "Otterbox\n",
      "Panasonic\n",
      "Phones\n",
      "Photoshop\n",
      "Pioneer\n",
      "Pirates\n",
      "Pirates of the Caribbean\n",
      "Play station 3\n",
      "Playbook\n",
      "Playstation\n",
      "Playstation 3\n",
      "Playstation 3 console\n",
      "Portable DVD player\n",
      "Power supply\n",
      "Printer\n",
      "Printers\n",
      "Projector\n",
      "Projectors\n",
      "Ps3\n",
      "Ps3 console\n",
      "Ps3 controller\n",
      "Ps3 games\n",
      "Ps3 headset\n",
      "Psp\n",
      "Radar detector\n",
      "Radio\n",
      "Razer\n",
      "Receiver\n",
      "Receivers\n",
      "Record player\n",
      "Red hot chili peppers\n",
      "Refrigerator\n",
      "Remote start\n",
      "Resistance 3\n",
      "Rio\n",
      "Rocksmith\n",
      "Roku\n",
      "Router\n",
      "Routers\n",
      "Samsung\n",
      "Samsung galaxy\n",
      "Samsung galaxy s2\n",
      "Samsung galaxy tab\n",
      "Samsung infuse\n",
      "Samsung laptop\n",
      "Samsung led\n",
      "Samsung refrigerator\n",
      "Samsung smart tv\n",
      "Samsung tablet\n",
      "Samsung tv\n",
      "Scanner\n",
      "Scarface\n",
      "Sd card\n",
      "Security camera\n",
      "Sennheiser\n",
      "Sharp\n",
      "Sims 3\n",
      "Sims 3 pets\n",
      "Sirius\n",
      "Skull candy\n",
      "Skullcandy\n",
      "Sling box\n",
      "Slingbox\n",
      "Smart tv\n",
      "Sonos\n",
      "Sons of anarchy\n",
      "Sony\n",
      "Sony camera\n",
      "Sony cybershot\n",
      "Sony google tv\n",
      "Sony headphones\n",
      "Sony laptop\n",
      "Sony laptops\n",
      "Sony tv\n",
      "Sony vaio\n",
      "Sound bar\n",
      "Soundbar\n",
      "Speaker wire\n",
      "Speakers\n",
      "Speck\n",
      "Star wars\n",
      "Star wars blu ray\n",
      "Starwars\n",
      "Stereo\n",
      "Stylus\n",
      "Subwoofer\n",
      "Subwoofers\n",
      "Supernatural\n",
      "Surge protector\n",
      "Surround sound\n",
      "Tablet\n",
      "Tablets\n",
      "Television\n",
      "The lion king\n",
      "The walking dead\n",
      "Thor\n",
      "Thrive\n",
      "TiVo\n",
      "Tivo\n",
      "Toshiba\n",
      "Toshiba laptop\n",
      "Toshiba thrive\n",
      "Touch pad\n",
      "Touchpad\n",
      "Transformer\n",
      "Transformers\n",
      "Transformers 3\n",
      "Transformers dark of the moon\n",
      "Tripod\n",
      "Tritton\n",
      "Turntable\n",
      "Turtle beach\n",
      "Turtle beaches\n",
      "Tv\n",
      "Tv antenna\n",
      "Tv mount\n",
      "Tv stand\n",
      "Tv stands\n",
      "Tv wall mount\n",
      "Tvs\n",
      "Uncharted\n",
      "Uncharted 3\n",
      "Universal remote\n",
      "Ups\n",
      "Vacuum\n",
      "Vaio\n",
      "Vampire diaries\n",
      "Viper\n",
      "Virgin mobile\n",
      "Vizio\n",
      "Voice recorder\n",
      "Wacom\n",
      "Wall mount\n",
      "Washer\n",
      "Watch the throne\n",
      "Waterproof camera\n",
      "Web cam\n",
      "Webcam\n",
      "Western digital\n",
      "Westinghouse\n",
      "Wii\n",
      "Wii console\n",
      "Windows 7\n",
      "Wireless adapter\n",
      "Wireless headphones\n",
      "Wireless keyboard\n",
      "Wireless mouse\n",
      "Wireless printer\n",
      "Wireless router\n",
      "Wireless routers\n",
      "Wireless speakers\n",
      "X men\n",
      "X men first class\n",
      "X-men\n",
      "X-men first class\n",
      "Xbox\n",
      "Xbox 360\n",
      "Xbox 360 console\n",
      "Xbox 360 controller\n",
      "Xbox console\n",
      "Xbox live\n",
      "Xbox360\n",
      "Xm radio\n",
      "Xmen\n",
      "Xmen first class\n",
      "Xoom\n",
      "Zagg\n",
      "Zumba\n",
      "Zune\n",
      "a630\n",
      "ac\n",
      "ac adapter\n",
      "acer\n",
      "acer iconia\n",
      "acer tablet\n",
      "action replay\n",
      "adapter\n",
      "adapters\n",
      "adobe\n",
      "air conditioner\n",
      "air conditioners\n",
      "air purifier\n",
      "akon\n",
      "alarm clock\n",
      "alarm clocks\n",
      "alienware\n",
      "alpine\n",
      "altec lansing\n",
      "amp\n",
      "amplifier\n",
      "amplifiers\n",
      "amps\n",
      "amy winehouse\n",
      "android tablet\n",
      "android tablets\n",
      "anime\n",
      "antec\n",
      "antenna\n",
      "antennas\n",
      "anti virus\n",
      "antivirus\n",
      "apc\n",
      "apple\n",
      "apple ipad\n",
      "apple ipod\n",
      "apple laptop\n",
      "apple laptops\n",
      "apple tv\n",
      "aquos\n",
      "archos\n",
      "arkham city\n",
      "asus\n",
      "asus laptop\n",
      "asus tablet\n",
      "asus transformer\n",
      "ati\n",
      "audio cable\n",
      "avatar\n",
      "averatec\n",
      "avril lavigne\n",
      "babylon 5\n",
      "backpack\n",
      "batman\n",
      "batman arkham city\n",
      "batteries\n",
      "battery\n",
      "battery backup\n",
      "battery charger\n",
      "battery chargers\n",
      "battlefield\n",
      "battlefield 2\n",
      "battlefield 3\n",
      "battlestar galactica\n",
      "beatles\n",
      "beats\n",
      "beats by dr dre\n",
      "beats by dre\n",
      "belkin\n",
      "beyonce\n",
      "big bang theory\n",
      "binoculars\n",
      "bionic\n",
      "blackberry\n",
      "blackberry playbook\n",
      "blank dvd\n",
      "blank media\n",
      "bleach\n",
      "blu ray\n",
      "blu ray player\n",
      "blu-ray\n",
      "blue ray\n",
      "blue tooth\n",
      "bluetooth\n",
      "bluetooth adapter\n",
      "bluetooth headphones\n",
      "bluetooth headset\n",
      "bluetooth headsets\n",
      "bluetooth mouse\n",
      "bluray\n",
      "bobby valentino\n",
      "bon jovi\n",
      "bone thugs\n",
      "bookworm\n",
      "boombox\n",
      "boost mobile\n",
      "bose\n",
      "bose headphones\n",
      "bose speakers\n",
      "bourne\n",
      "brad paisley\n",
      "braun\n",
      "bridesmaids\n",
      "buffalo\n",
      "cable\n",
      "cable modem\n",
      "cablecard\n",
      "cables\n",
      "calculator\n",
      "calculators\n",
      "call of duty\n",
      "camcorder\n",
      "camcorders\n",
      "camera\n",
      "camera bag\n",
      "camera case\n",
      "camera cases\n",
      "cameras\n",
      "cannon\n",
      "canon\n",
      "canon a630\n",
      "canon digital camera\n",
      "canon g7\n",
      "canon lens\n",
      "canon powershot\n",
      "canon sd1000\n",
      "captain america\n",
      "capture card\n",
      "car\n",
      "car alarm\n",
      "car alarms\n",
      "car audio\n",
      "car dvd\n",
      "car dvd player\n",
      "car radio\n",
      "car radios\n",
      "car speakers\n",
      "car stereo\n",
      "car stereos\n",
      "card reader\n",
      "carrie underwood\n",
      "cars\n",
      "carter 4\n",
      "case\n",
      "case logic\n",
      "cases\n",
      "casio\n",
      "casio exilim\n",
      "cd\n",
      "cd burner\n",
      "cd case\n",
      "cd cases\n",
      "cd changer\n",
      "cd player\n",
      "cd players\n",
      "cd recorder\n",
      "cd storage\n",
      "cd-r\n",
      "cds\n",
      "cell phone\n",
      "cell phones\n",
      "cellphones\n",
      "chair\n",
      "chairs\n",
      "charger\n",
      "chargers\n",
      "charmed\n",
      "chocolatier\n",
      "civilization\n",
      "clearance\n",
      "clock\n",
      "clock radio\n",
      "coffee maker\n",
      "comcast\n",
      "command and conquer\n",
      "common\n",
      "compact flash\n",
      "compact refrigerator\n",
      "compaq\n",
      "computer\n",
      "computer case\n",
      "computer desk\n",
      "computer desks\n",
      "computer games\n",
      "computer memory\n",
      "computer monitor\n",
      "computer monitors\n",
      "computer speakers\n",
      "computers\n",
      "converter\n",
      "converter box\n",
      "copier\n",
      "cordless phone\n",
      "cordless phones\n",
      "cpu\n",
      "creative\n",
      "creative zen\n",
      "csi\n",
      "cybershot\n",
      "d-link\n",
      "d40\n",
      "dance dance revolution\n",
      "dane cook\n",
      "dazzle\n",
      "ddr\n",
      "ddr2\n",
      "dead island\n",
      "deadwood\n",
      "dehumidifier\n",
      "dell\n",
      "dell laptop\n",
      "dell laptops\n",
      "denon\n",
      "desk\n",
      "desks\n",
      "desktop\n",
      "die hard\n",
      "digital camera\n",
      "digital cameras\n",
      "digital frame\n",
      "digital frames\n",
      "digital photo frame\n",
      "digital photo frames\n",
      "digital picture frame\n",
      "digital picture frames\n",
      "digital recorder\n",
      "digital voice recorder\n",
      "direct tv\n",
      "directv\n",
      "dirt\n",
      "dishwasher\n",
      "dishwashers\n",
      "disney\n",
      "disturbia\n",
      "dlink\n",
      "dlp\n",
      "docking station\n",
      "dr dre beats\n",
      "dragon ball z\n",
      "dragonball z\n",
      "drake\n",
      "dre beats\n",
      "dream theater\n",
      "dreamgirls\n",
      "droid bionic\n",
      "dryer\n",
      "ds\n",
      "ds games\n",
      "ds lite\n",
      "dsc-h2\n",
      "dsc-h5\n",
      "dsc-h7\n",
      "dsl\n",
      "dsl modem\n",
      "dual\n",
      "dv2000\n",
      "dv6000\n",
      "dv9000\n",
      "dvd\n",
      "dvd burner\n",
      "dvd burners\n",
      "dvd case\n",
      "dvd cases\n",
      "dvd drive\n",
      "dvd player\n",
      "dvd players\n",
      "dvd r\n",
      "dvd rack\n",
      "dvd recorder\n",
      "dvd recorders\n",
      "dvd rw\n",
      "dvd storage\n",
      "dvd-r\n",
      "dvd-rw\n",
      "dvds\n",
      "dvi\n",
      "dvi cable\n",
      "dvi-d\n",
      "dvr\n",
      "dynex\n",
      "dyson\n",
      "ear buds\n",
      "earbuds\n",
      "earphones\n",
      "elite\n",
      "emachines\n",
      "eminem\n",
      "employment\n",
      "enclosure\n",
      "entertainment center\n",
      "entertainment centers\n",
      "entourage\n",
      "epilator\n",
      "epson\n",
      "equalizer\n",
      "esata\n",
      "ethernet\n",
      "ethernet cable\n",
      "ethernet card\n",
      "eureka\n",
      "evga\n",
      "evo\n",
      "evo 3d\n",
      "external drive\n",
      "external dvd\n",
      "external dvd burner\n",
      "external hard drive\n",
      "external hard drives\n",
      "external harddrive\n",
      "external harddrives\n",
      "external hardrive\n",
      "fabolous\n",
      "fall out boy\n",
      "family guy\n",
      "fan\n",
      "fans\n",
      "fantastic four\n",
      "fast five\n",
      "fax\n",
      "fax machine\n",
      "fax machines\n",
      "fergie\n",
      "fifa 12\n",
      "final fantasy\n",
      "firelite\n",
      "firewire\n",
      "firewire cable\n",
      "five finger death punch\n",
      "flash\n",
      "flash drive\n",
      "flash drives\n",
      "flash memory\n",
      "flashdrive\n",
      "flat screen tv\n",
      "flatout\n",
      "flip\n",
      "flyer\n",
      "fm transmitter\n",
      "forza\n",
      "forza 2\n",
      "frame\n",
      "freezer\n",
      "freezers\n",
      "fridge\n",
      "friends\n",
      "frigidaire\n",
      "frontpage\n",
      "fuji\n",
      "furniture\n",
      "galaxy\n",
      "galaxy tab\n",
      "galaxy tab 10.1\n",
      "game boy\n",
      "gameboy\n",
      "gameboy advance\n",
      "gamecube\n",
      "games\n",
      "gameshark\n",
      "garmin\n",
      "garmin gps\n",
      "garmin nuvi\n",
      "garmin nuvi 350\n",
      "gateway\n",
      "gears of war\n",
      "gears of war 3\n",
      "geforce\n",
      "genesis\n",
      "ghost recon\n",
      "ghost rider\n",
      "gilmore girls\n",
      "go pro\n",
      "god of war\n",
      "godfather\n",
      "google tv\n",
      "gopro\n",
      "gps\n",
      "gps navigation\n",
      "grand theft auto\n",
      "graphics card\n",
      "graphics cards\n",
      "green day\n",
      "green lantern\n",
      "greys anatomy\n",
      "griffin\n",
      "grill\n",
      "grindhouse\n",
      "guild wars\n",
      "guitar\n",
      "guitar hero\n",
      "guitar hero 2\n",
      "guitar hero 3\n",
      "guitar hero ii\n",
      "guitars\n",
      "hairspray\n",
      "halo\n",
      "halo 2\n",
      "halo 3\n",
      "hannah montana\n",
      "hard drive\n",
      "hard drive enclosure\n",
      "hard drives\n",
      "harddrive\n",
      "harddrives\n",
      "harmon kardon\n",
      "harmony\n",
      "harry potter\n",
      "hd\n",
      "hd antenna\n",
      "hd dvd\n",
      "hd dvd player\n",
      "hd radio\n",
      "hd tv\n",
      "hd-dvd\n",
      "hdmi\n",
      "hdmi cable\n",
      "hdmi cables\n",
      "hdtv\n",
      "hdtv antenna\n",
      "head phones\n",
      "headphone\n",
      "headphones\n",
      "headset\n",
      "headsets\n",
      "heatsink\n",
      "hello kitty\n",
      "heroes\n",
      "high school musical\n",
      "hitachi\n",
      "home theater\n",
      "hoover\n",
      "hot fuzz\n",
      "house\n",
      "hp\n",
      "hp laptop\n",
      "hp laptops\n",
      "hp notebook\n",
      "hp pavilion\n",
      "hp printer\n",
      "hp printers\n",
      "hp tablet\n",
      "hp touch\n",
      "hp touch pad\n",
      "hp touchpad\n",
      "htc\n",
      "htc evo\n",
      "htc flyer\n",
      "htc inspire\n",
      "htc tablet\n",
      "hub\n",
      "i pad\n",
      "i phone\n",
      "i pod\n",
      "i pods\n",
      "i-pod\n",
      "iMac\n",
      "iPad\n",
      "iPad 2\n",
      "iPad 2 case\n",
      "iPad case\n",
      "iPad keyboard\n",
      "iPhone\n",
      "iPhone 4\n",
      "iPhone 4 case\n",
      "iPhone 4 cases\n",
      "iPhone 4S\n",
      "iPhone 4s\n",
      "iPhone 4s case\n",
      "iPhone 4s cases\n",
      "iPhone accessories\n",
      "iPhone case\n",
      "iPhone cases\n",
      "iPhone charger\n",
      "iPhone dock\n",
      "iPod\n",
      "iPod dock\n",
      "iPod nano\n",
      "iPod speakers\n",
      "iPod touch\n",
      "iPod touch case\n",
      "iPod touch cases\n",
      "ibook\n",
      "ice maker\n",
      "ico\n",
      "iconia\n",
      "ihome\n",
      "iluv\n",
      "imac\n",
      "incubus\n",
      "ink\n",
      "inno\n",
      "insignia\n",
      "intel\n",
      "internal hard drive\n",
      "inuyasha\n",
      "inverter\n",
      "ipad\n",
      "ipad 2\n",
      "ipad2\n",
      "ipaq\n",
      "iphone\n",
      "iphone 4\n",
      "iphone 4s\n",
      "ipod\n",
      "ipod accesories\n",
      "ipod accessories\n",
      "ipod car\n",
      "ipod car adapter\n",
      "ipod case\n",
      "ipod cases\n",
      "ipod charger\n",
      "ipod dock\n",
      "ipod headphones\n",
      "ipod mini\n",
      "ipod nano\n",
      "ipod shuffle\n",
      "ipod speaker\n",
      "ipod speakers\n",
      "ipod touch\n",
      "ipod video\n",
      "ipods\n",
      "iriver\n",
      "itouch\n",
      "itrip\n",
      "itunes\n",
      "jabra\n",
      "james bond\n",
      "jawbone\n",
      "jbl\n",
      "jobs\n",
      "joe\n",
      "john mayer\n",
      "joystick\n",
      "jump drive\n",
      "jurassic park\n",
      "just dance 3\n",
      "justin timberlake\n",
      "jvc\n",
      "kanye west\n",
      "karaoke\n",
      "kaspersky\n",
      "kelly clarkson\n",
      "kensington\n",
      "kenwood\n",
      "keurig\n",
      "keyboard\n",
      "keyboards\n",
      "keyless entry\n",
      "kicker\n",
      "kindle\n",
      "kindle fire\n",
      "kinect\n",
      "king of queens\n",
      "kingston\n",
      "kiss\n",
      "klipsch\n",
      "kodak\n",
      "kodak easyshare\n",
      "korn\n",
      "kvm\n",
      "kvm switch\n",
      "labtop\n",
      "labtops\n",
      "lacie\n",
      "lady gaga\n",
      "laminator\n",
      "lap top\n",
      "lap tops\n",
      "laptop\n",
      "laptop bag\n",
      "laptop bags\n",
      "laptop battery\n",
      "laptop case\n",
      "laptop cases\n",
      "laptop charger\n",
      "laptop hard drive\n",
      "laptops\n",
      "laser printer\n",
      "lcd\n",
      "lcd monitor\n",
      "lcd monitors\n",
      "lcd tv\n",
      "led tv\n",
      "led zeppelin\n",
      "lenovo\n",
      "lens\n",
      "lenses\n",
      "lg\n",
      "lifehouse\n",
      "lightscribe\n",
      "lil wayne\n",
      "linkin park\n",
      "linksys\n",
      "linksys router\n",
      "lion king\n",
      "logitech\n",
      "logitech revue\n",
      "lord of the rings\n",
      "lost\n",
      "lowepro\n",
      "lumix\n",
      "mac\n",
      "mac book\n",
      "mac book pro\n",
      "mac mini\n",
      "macbook\n",
      "macbook air\n",
      "macbook pro\n",
      "madden\n",
      "madden 08\n",
      "madden 12\n",
      "magellan\n",
      "magnolia\n",
      "marilyn manson\n",
      "marine\n",
      "mario\n",
      "mario party\n",
      "mario party 8\n",
      "maroon 5\n",
      "martin\n",
      "masters of horror\n",
      "matrix\n",
      "maxtor\n",
      "mcafee\n",
      "media storage\n",
      "megadeth\n",
      "memory\n",
      "memory card\n",
      "memory card reader\n",
      "memory cards\n",
      "memory stick\n",
      "memory stick duo\n",
      "memory stick pro duo\n",
      "memory sticks\n",
      "metallica\n",
      "mic\n",
      "mice\n",
      "michael buble\n",
      "micro sd\n",
      "micro sd card\n",
      "microphone\n",
      "microphones\n",
      "microsd\n",
      "microsoft\n",
      "microsoft access\n",
      "microsoft office\n",
      "microsoft office 2003\n",
      "microsoft office 2007\n",
      "microsoft word\n",
      "microwave\n",
      "microwave oven\n",
      "microwaves\n",
      "mike jones\n",
      "mini dv\n",
      "mini fridge\n",
      "mini sd\n",
      "mini sd card\n",
      "minisd\n",
      "modem\n",
      "modems\n",
      "modern warfare 3\n",
      "monitor\n",
      "monitors\n",
      "monster\n",
      "monster cable\n",
      "monster squad\n",
      "motherboard\n",
      "motorola\n",
      "motorola triumph\n",
      "motorola xoom\n",
      "mouse\n",
      "mouse pad\n",
      "movies\n",
      "mp3\n",
      "mp3 player\n",
      "mp3 players\n",
      "mp4\n",
      "music\n",
      "my book\n",
      "my chemical romance\n",
      "nancy drew\n",
      "nano\n",
      "naruto\n",
      "nas\n",
      "nascar 08\n",
      "navigation\n",
      "navigation system\n",
      "ne-yo\n",
      "need for speed\n",
      "nero\n",
      "netbook\n",
      "netbooks\n",
      "netgear\n",
      "network cable\n",
      "network card\n",
      "nexus s\n",
      "neyo\n",
      "nickelback\n",
      "nikon\n",
      "nikon d40\n",
      "nikon d40x\n",
      "nikon d80\n",
      "nikon lens\n",
      "nine inch nails\n",
      "nintendo\n",
      "nintendo ds\n",
      "nintendo ds games\n",
      "nintendo ds lite\n",
      "nintendo wii\n",
      "nintendo wii console\n",
      "nintendo wii system\n",
      "nokia\n",
      "nook\n",
      "nook color\n",
      "norton\n",
      "norton 360\n",
      "norton antivirus\n",
      "notebook\n",
      "notebook case\n",
      "notebook cases\n",
      "notebook hard drive\n",
      "notebook memory\n",
      "notebooks\n",
      "nuvi\n",
      "nvidia\n",
      "oblivion\n",
      "odin sphere\n",
      "office\n",
      "office 2003\n",
      "office 2007\n",
      "olevia\n",
      "olympus\n",
      "on star\n",
      "one tree hill\n",
      "onerepublic\n",
      "onkyo\n",
      "onstar\n",
      "original soundtrack\n",
      "otterbox\n",
      "outdoor speaker\n",
      "outdoor speakers\n",
      "overlord\n",
      "ozzy\n",
      "ozzy osbourne\n",
      "palm\n",
      "palm pilot\n",
      "panasonic\n",
      "panasonic plasma\n",
      "pandigital\n",
      "pans labyrinth\n",
      "paper shredder\n",
      "paramore\n",
      "paul mccartney\n",
      "pc games\n",
      "pc speakers\n",
      "pc133\n",
      "pc2100\n",
      "pc2700\n",
      "pc3200\n",
      "pc4200\n",
      "pcmcia\n",
      "pda\n",
      "pearl jam\n",
      "pedometer\n",
      "pen drive\n",
      "pentax\n",
      "philips\n",
      "phillips\n",
      "phone\n",
      "phones\n",
      "photo frame\n",
      "photo paper\n",
      "photo printer\n",
      "photo printers\n",
      "photoshop\n",
      "piano\n",
      "picture frame\n",
      "pink\n",
      "pink floyd\n",
      "pinnacle\n",
      "pioneer\n",
      "pirates\n",
      "pirates of the caribbean\n",
      "planet earth\n",
      "plantronics\n",
      "plasma\n",
      "plasma tv\n",
      "play station\n",
      "play station 2\n",
      "play station 3\n",
      "playbook\n",
      "playstation\n",
      "playstation 2\n",
      "playstation 3\n",
      "playstation 3 console\n",
      "playstation3\n",
      "plextor\n",
      "pocket pc\n",
      "pokemon\n",
      "pokemon diamond\n",
      "polaroid\n",
      "portable air conditioner\n",
      "portable cd player\n",
      "portable dvd\n",
      "portable dvd player\n",
      "portable dvd players\n",
      "portable hard drive\n",
      "portable printer\n",
      "portable speakers\n",
      "portable tv\n",
      "portal2\n",
      "power adapter\n",
      "power cord\n",
      "power inverter\n",
      "power supplies\n",
      "power supply\n",
      "powerpoint\n",
      "price match\n",
      "prince\n",
      "print server\n",
      "printer\n",
      "printer ink\n",
      "printers\n",
      "prison break\n",
      "privacy screen\n",
      "pro duo\n",
      "processor\n",
      "projector\n",
      "projector screen\n",
      "projector screens\n",
      "projectors\n",
      "ps2\n",
      "ps2 games\n",
      "ps3\n",
      "ps3 console\n",
      "ps3 games\n",
      "ps3 headset\n",
      "psp\n",
      "psp games\n",
      "psp movies\n",
      "puddle of mudd\n",
      "q1\n",
      "qam\n",
      "queen\n",
      "quickbooks\n",
      "quicken\n",
      "r kelly\n",
      "r. kelly\n",
      "radar\n",
      "radar detector\n",
      "radar detectors\n",
      "radio\n",
      "radios\n",
      "ram\n",
      "razer\n",
      "razr\n",
      "rca\n",
      "reba\n",
      "receiver\n",
      "receivers\n",
      "rechargeable batteries\n",
      "record player\n",
      "recorder\n",
      "refridgerator\n",
      "refrigerator\n",
      "refrigerators\n",
      "registry\n",
      "remote\n",
      "remote control\n",
      "remote start\n",
      "rescue me\n",
      "resident evil\n",
      "resident evil 4\n",
      "resistance 3\n",
      "rihanna\n",
      "rock band\n",
      "rocketfish\n",
      "roku\n",
      "rolling stones\n",
      "rome\n",
      "router\n",
      "routers\n",
      "roxio\n",
      "rush\n",
      "s video\n",
      "s video cable\n",
      "s-video\n",
      "s-video cable\n",
      "samsung\n",
      "samsung dlp\n",
      "samsung galaxy\n",
      "samsung galaxy tab\n",
      "samsung galaxy tablet\n",
      "samsung laptop\n",
      "samsung lcd\n",
      "samsung tablet\n",
      "samsung tv\n",
      "sandisk\n",
      "sanus\n",
      "sata\n",
      "sata cable\n",
      "satelite radio\n",
      "satellite radio\n",
      "scanner\n",
      "scanners\n",
      "scarface\n",
      "scrubs\n",
      "sd\n",
      "sd card\n",
      "sd cards\n",
      "sd memory\n",
      "sd memory card\n",
      "sd600\n",
      "sd750\n",
      "sd800\n",
      "sd800is\n",
      "sd850\n",
      "seagate\n",
      "sean kingston\n",
      "security\n",
      "security camera\n",
      "seinfeld\n",
      "sennheiser\n",
      "sex and the city\n",
      "shadowrun\n",
      "sharp\n",
      "sharp aquos\n",
      "shaver\n",
      "shooter\n",
      "shredder\n",
      "shrek\n",
      "shuffle\n",
      "shure\n",
      "simpsons\n",
      "sims\n",
      "sims 2\n",
      "sirius\n",
      "sirius radio\n",
      "skull candy\n",
      "skullcandy\n",
      "sling box\n",
      "slingbox\n",
      "smallville\n",
      "smashing pumpkins\n",
      "software\n",
      "sonos\n",
      "sons of anarchy\n",
      "sony\n",
      "sony bravia\n",
      "sony camcorder\n",
      "sony camera\n",
      "sony cybershot\n",
      "sony digital camera\n",
      "sony headphones\n",
      "sony home theatre\n",
      "sony laptop\n",
      "sony lcd\n",
      "sony psp\n",
      "sony tv\n",
      "sony vaio\n",
      "sopranos\n",
      "sound bar\n",
      "sound card\n",
      "sound cards\n",
      "soundbar\n",
      "south park\n",
      "speaker\n",
      "speaker stand\n",
      "speaker stands\n",
      "speaker wire\n",
      "speakers\n",
      "spider-man 3\n",
      "spiderman\n",
      "spiderman 3\n",
      "splitter\n",
      "sprint\n",
      "sprint phones\n",
      "stand\n",
      "stands\n",
      "star trek\n",
      "star wars\n",
      "star wars blu ray\n",
      "starcraft\n",
      "stargate\n",
      "stereo\n",
      "stereos\n",
      "stomp the yard\n",
      "storage\n",
      "stove\n",
      "stylus\n",
      "subwoofer\n",
      "subwoofers\n",
      "superman\n",
      "supernatural\n",
      "surge\n",
      "surge protector\n",
      "surge protectors\n",
      "surround sound\n",
      "switch\n",
      "t pain\n",
      "t-mobile\n",
      "t-pain\n",
      "t.i.\n",
      "tablet\n",
      "tablet pc\n",
      "tablets\n",
      "tank\n",
      "tape recorder\n",
      "targus\n",
      "telephone\n",
      "telephones\n",
      "television\n",
      "televisions\n",
      "terk\n",
      "the beatles\n",
      "the bigs\n",
      "the carter 4\n",
      "the darkness\n",
      "the hills\n",
      "the lion king\n",
      "the oc\n",
      "the office\n",
      "the secret\n",
      "the shield\n",
      "the simpsons\n",
      "the sims\n",
      "the sims 2\n",
      "the sopranos\n",
      "the used\n",
      "the wire\n",
      "thor\n",
      "three 6 mafia\n",
      "three six mafia\n",
      "thrive\n",
      "thumb drive\n",
      "ti\n",
      "tim mcgraw\n",
      "timbaland\n",
      "tivo\n",
      "tmnt\n",
      "toaster oven\n",
      "tom tom\n",
      "tomb raider\n",
      "tomtom\n",
      "tool\n",
      "toontown\n",
      "toshiba\n",
      "toshiba laptop\n",
      "toshiba thrive\n",
      "toslink\n",
      "touch pad\n",
      "touchpad\n",
      "toughbook\n",
      "transformer\n",
      "transformers\n",
      "transformers 3\n",
      "transformers dark of the moon\n",
      "treadmill\n",
      "treadmills\n",
      "trendnet\n",
      "treo\n",
      "tripod\n",
      "tuner\n",
      "turntable\n",
      "turntables\n",
      "turtle beach\n",
      "tv\n",
      "tv antenna\n",
      "tv mount\n",
      "tv mounts\n",
      "tv stand\n",
      "tv stands\n",
      "tv tuner\n",
      "tv wall mount\n",
      "tv wall mounts\n",
      "tvs\n",
      "ugk\n",
      "umd\n",
      "uniden\n",
      "universal remote\n",
      "ups\n",
      "usb\n",
      "usb adapter\n",
      "usb cable\n",
      "usb cables\n",
      "usb drive\n",
      "usb flash\n",
      "usb flash drive\n",
      "usb hard drive\n",
      "usb headset\n",
      "usb hub\n",
      "usb memory\n",
      "usb wireless\n",
      "v-moda\n",
      "vacuum\n",
      "vacuums\n",
      "vaio\n",
      "various artists\n",
      "vcr\n",
      "velvet revolver\n",
      "verbatim\n",
      "verizon\n",
      "vga\n",
      "vga cable\n",
      "vhs\n",
      "video camera\n",
      "video capture\n",
      "video card\n",
      "video cards\n",
      "video games\n",
      "video ipod\n",
      "viper\n",
      "virgin mobile\n",
      "visio\n",
      "vista\n",
      "vizio\n",
      "voice recorder\n",
      "voice recorders\n",
      "voip\n",
      "vonage\n",
      "vtech\n",
      "wacom\n",
      "walkie talkie\n",
      "walkman\n",
      "wall mount\n",
      "wall mounts\n",
      "warcraft\n",
      "warcraft 3\n",
      "washer\n",
      "washers\n",
      "watch the throne\n",
      "waterproof\n",
      "wavebird\n",
      "weather radio\n",
      "web cam\n",
      "web camera\n",
      "web cams\n",
      "webcam\n",
      "weeds\n",
      "western digital\n",
      "westinghouse\n",
      "whirlpool\n",
      "white stripes\n",
      "wi\n",
      "wifi\n",
      "wii\n",
      "wii console\n",
      "wii game system\n",
      "wii games\n",
      "wii hardware\n",
      "wii play\n",
      "wii system\n",
      "wild hogs\n",
      "windows\n",
      "windows 7\n",
      "windows vista\n",
      "windows xp\n",
      "wine\n",
      "wine cooler\n",
      "wireless\n",
      "wireless adapter\n",
      "wireless card\n",
      "wireless cards\n",
      "wireless headphones\n",
      "wireless internet\n",
      "wireless keyboard\n",
      "wireless modem\n",
      "wireless mouse\n",
      "wireless printer\n",
      "wireless router\n",
      "wireless routers\n",
      "wireless speaker\n",
      "wireless speakers\n",
      "wireless usb\n",
      "world of warcraft\n",
      "wrt54g\n",
      "wwe\n",
      "x box\n",
      "x box 360\n",
      "x-box 360\n",
      "x-files\n",
      "xbox\n",
      "xbox 360\n",
      "xbox 360 console\n",
      "xbox 360 elite\n",
      "xbox 360 games\n",
      "xbox console\n",
      "xbox elite\n",
      "xbox games\n",
      "xbox live\n",
      "xbox360\n",
      "xd\n",
      "xenosaga\n",
      "xm\n",
      "xm radio\n",
      "xmen\n",
      "xmen first class\n",
      "xoom\n",
      "xp\n",
      "yamaha\n",
      "young jeezy\n",
      "zelda\n",
      "zen\n",
      "zodiac\n",
      "zonealarm\n",
      "zumba\n",
      "zune\n"
     ]
    }
   ],
   "source": [
    "for query in gset['query'].unique():\n",
    "    print(query)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
